package com.ruoyi.business.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.JtProductSn;
import com.ruoyi.business.service.IJtProductSnService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 产品序列号Controller
 * 
 * @author Alan Zhang
 * @date 2025-05-22
 */
@Controller
@RequestMapping("/business/product/sn")
public class JtProductSnController extends BaseController
{
    private String prefix = "business/product/sn";

    @Autowired
    private IJtProductSnService jtProductSnService;

    @RequiresPermissions("business:sn:view")
    @GetMapping("/{productId}")
    public String sn(@PathVariable("productId") Long productId,  ModelMap mmap)
    {
        mmap.put("productId", productId);
        return prefix + "/sn";
    }

    /**
     * 查询产品序列号列表
     */
    @RequiresPermissions("business:sn:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JtProductSn jtProductSn)
    {
        startPage();
        List<JtProductSn> list = jtProductSnService.selectJtProductSnList(jtProductSn);
        return getDataTable(list);
    }

    /**
     * 导出产品序列号列表
     */
    @RequiresPermissions("business:sn:export")
    @Log(title = "产品序列号", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JtProductSn jtProductSn)
    {
        List<JtProductSn> list = jtProductSnService.selectJtProductSnList(jtProductSn);
        ExcelUtil<JtProductSn> util = new ExcelUtil<JtProductSn>(JtProductSn.class);
        return util.exportExcel(list, "产品序列号数据");
    }

    /**
     * 新增产品序列号
     */
    @RequiresPermissions("business:sn:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存产品序列号
     */
    @RequiresPermissions("business:sn:add")
    @Log(title = "产品序列号", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JtProductSn jtProductSn)
    {
        return toAjax(jtProductSnService.insertJtProductSn(jtProductSn));
    }

    /**
     * 修改产品序列号
     */
    @RequiresPermissions("business:sn:edit")
    @GetMapping("/edit/{snId}")
    public String edit(@PathVariable("snId") Long snId, ModelMap mmap)
    {
        JtProductSn jtProductSn = jtProductSnService.selectJtProductSnBySnId(snId);
        mmap.put("jtProductSn", jtProductSn);
        return prefix + "/edit";
    }

    /**
     * 修改保存产品序列号
     */
    @RequiresPermissions("business:sn:edit")
    @Log(title = "产品序列号", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JtProductSn jtProductSn)
    {
        return toAjax(jtProductSnService.updateJtProductSn(jtProductSn));
    }

    /**
     * 删除产品序列号
     */
    @RequiresPermissions("business:sn:remove")
    @Log(title = "产品序列号", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jtProductSnService.deleteJtProductSnBySnIds(ids));
    }
}
